package cn.youwan.market.adapter;

import java.util.ArrayList;
import java.util.List;

import cn.youwan.market.R;
import cn.youwan.market.RecommendActivity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
public class GridViewAdapter extends BaseAdapter{

	private List<String> games;
	private Context context;

	public GridViewAdapter(List<String> games,Context context){
		if(games!=null&games.size()>0){
			this.games=games;
		}else{
			this.games=new ArrayList<String>();
		}
		this.context=context;
	}
	
	public void chooseAll(){
		notifyDataSetChanged();
		RecommendActivity.ins=new ArrayList<String>();
		RecommendActivity.ins=games;
	}
	
	
	@Override
	public int getCount() {
		return games.size();
	}

	@Override
	public Object getItem(int position) {
		return games.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View v, ViewGroup arg2) {
		v=LayoutInflater.from(context).inflate(R.layout.test_recommend_item, null);
		final ImageView iv_check = (ImageView)v.findViewById(R.id.iv_check);
		ImageView iv_recommend = (ImageView)v.findViewById(R.id.iv_recommend);
		iv_recommend.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				boolean isExists=false;
				if(iv_check.getVisibility()==View.GONE){
					iv_check.setVisibility(View.VISIBLE);
//					for(String s:RecommendActivity.ins){
//						if(s.equals(games.get(position))){
//							isExists=true;
//						}
//					}
//					if(!isExists){
//						RecommendActivity.ins.add(games.get(position));
//					}
					RecommendActivity.ins.add(games.get(position));
				}else{
					iv_check.setVisibility(View.GONE);
					RecommendActivity.ins.remove(games.get(position));
				}
			}
		});
		return v;
	}

}
